import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_page.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_b_department_all_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_user_by_id_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/risk_security_identification_page/risk_on_click_add_unit_page/risk_on_click_add_unit_page_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///风险管控-》安全风险辨识-》点击+新增界面 单元新增
class RiskOnClickAddUnitPagePage extends StatelessWidget {
  RiskOnClickAddUnitPagePage({super.key});

  final controller = Get.put(RiskOnClickAddUnitPageController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Scaffold(
          backgroundColor: AppColors.bg_color_grey,
          appBar: CustomAppBar(
            titleText: controller.addAndUpdate ? '新增' : '编辑',
          ),
          body: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(top: 10.w),
                  padding: EdgeInsets.only(left: 16.w, right: 20.w),
                  color: Colors.white,
                  child: Column(
                    children: [
                      CustomInputPage(
                        title: '风险分析单元名称',
                        isRequired: true,
                        isEnabled: true,
                        text: controller.riskObjectName,
                        onCallBack: (value) {
                          controller.riskObjectName = value;
                        },
                      ),
                      Row(
                        children: [
                          Text(
                            '*',
                            style: TextStyle(
                              fontSize: 14.sp,
                              height: 1.2,
                              color: AppColors.meaning_color_danger,
                            ),
                          ),
                          Text(
                            '责任部门：',
                            style: TextStyle(
                              fontSize: 14.sp,
                              height: 1.2,
                              color: AppColors.font_color_black,
                            ),
                          ),
                          AppGaps.hGap6,
                          Expanded(
                              child: Container(
                                  height: 50.w,
                                  alignment: Alignment.centerRight,
                                  child: Text(
                                    controller.departmentName,
                                    style: TextStyle(
                                      fontSize: 14.sp,
                                      height: 1.2,
                                      color: const Color(0xFF262F38),
                                    ),
                                  ))),
                        ],
                      ),
                      Row(
                        children: [
                          Text(
                            '*',
                            style: TextStyle(
                              fontSize: 14.sp,
                              height: 1.2,
                              color: AppColors.meaning_color_danger,
                            ),
                          ),
                          Text(
                            '责任人：',
                            style: TextStyle(
                              fontSize: 14.sp,
                              height: 1.2,
                              color: AppColors.font_color_black,
                            ),
                          ),
                          AppGaps.hGap6,
                          Expanded(
                              child: Container(
                                  height: 50.w,
                                  alignment: Alignment.centerRight,
                                  child: Text(
                                    controller.username,
                                    style: TextStyle(
                                      fontSize: 14.sp,
                                      height: 1.2,
                                      color: const Color(0xFF262F38),
                                    ),
                                  ))),
                        ],
                      ),
                      CustomSelectPage(
                          isEnabled: true,
                          selectText: controller.bDepartmentName,
                          title: '风险分析单元辨识部门：',
                          hintText: '请选择',
                          onCallBack: () {
                            Get.toNamed(AppRoutes.doublePreventionDepartmentSelection, arguments: {
                              'isRadio': true,
                            })?.then((value) {
                              //如果不为空则设置部门信息
                              if (value != null) {
                                final List<GetBDepartmentAllEntity> selectedList = value as List<GetBDepartmentAllEntity>;
                                controller.bDepartmentName = selectedList[0].departmentName!;
                                controller.bDepartmentId = selectedList[0].id!;
                                controller.isUpdate();
                              }
                            });
                          }),

                      Visibility(
                        visible: controller.bDepartmentName.isNotEmpty ? true : false,
                        child: CustomSelectPage(
                            isEnabled: true,
                            selectText: controller.bDusername,
                            title: '风险分析单元辨识人：',
                            hintText: '请选择',
                            onCallBack: () {
                              Get.toNamed(AppRoutes.doublePreventionPeopleSelection, arguments: {
                                'departmentId': controller.bDepartmentId,
                                'isRadio': true,
                              })?.then((value) {
                                final List<GetUserByIdEntity> selectedList = value as List<GetUserByIdEntity>;
                                controller.bDusername = selectedList[0].nickname!;
                                controller.bDid = selectedList[0].id!;
                                controller.isUpdate();
                              });
                            }),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          bottomSheet: Container(
            width: double.infinity,
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: 120.w,
                  height: 40.w,
                  child: ElevatedButton(
                      style: ElevatedButton.styleFrom(
                          backgroundColor: const Color(0xffFFFFFF),
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(22.r),
                          ),
                          side: BorderSide(
                            color: const Color(0xff5C6DFF),
                            width: 1.w, // 设置边框线的宽度
                          )),
                      onPressed: () {},
                      child: Text(
                        '取消',
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: const Color(0xff5C6DFF),
                          fontWeight: FontWeight.w400,
                        ),
                      )),
                ),
                SizedBox(
                  width: 202.w,
                  height: 40.w,
                  child: ElevatedButton(
                      style: ElevatedButton.styleFrom(
                        backgroundColor: AppColors.blue_button,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(22.r),
                        ),
                      ),
                      onPressed: controller.addRiskObject,
                      child: Text(
                        '确定',
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: Colors.white,
                          fontWeight: FontWeight.w400,
                        ),
                      )),
                )
              ],
            ),
          ),
        );
      },
    );
  }
}
